﻿using SqLiteHelper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dwg_output
{
    class Wire_ReadSQL
    {

        public static List<List<string>> ReadTagFromSql(string DBpath,int tag_id,int jigui_id)
        {



            //查询数据库的值
            SQLiteHelperV2 search_value = new SQLiteHelperV2(DBpath );

            string sql_jigui = "SELECT * FROM tagInfo WHERE card_id = @card_id AND area_id = @area_id";
            SQLiteParameter[] param = new SQLiteParameter[]{
                                   new SQLiteParameter("@card_id", tag_id),
                                   new SQLiteParameter("@area_id", jigui_id),
                                  

                                 };

            List<List<string>> TagRead = search_value.getDBValues_v2(sql_jigui,param);

            return TagRead;

        }

        public static List<string>ReadJiguiFromSql(string DBpath, int i)//返回一个机柜名称
        {



            //查询数据库的值
            SQLiteHelperV2 search_value = new SQLiteHelperV2(DBpath );
            string sql_jigui = string.Format("SELECT name FROM jigui  ");
             List<string> JiguiRead = search_value.getDBValues(sql_jigui);

            return JiguiRead;



        }


        public static int ReadJigui_ID_FromSql(string DBpath, string jigui_name)//返回一个机柜编号
        {
            string jiguiID = string.Format("SELECT id FROM jigui WHERE name = '{0}'", jigui_name);
            SQLiteHelperV2 id_value = new SQLiteHelperV2(DBpath);
            List<string> jiguiStringID = id_value.getDBValues(jiguiID);

            return int.Parse(jiguiStringID[0]);
        }



        public static int Read_Max_card_id(string DBpath, string jigui_name)
        {
            string jiguiID = "SELECT MAX(card_id) FROM  tagInfo";
            SQLiteHelperV2 id_value = new SQLiteHelperV2(DBpath);
            List<string> jiguiStringID = id_value.getDBValues(jiguiID) ;

            return int.Parse(jiguiStringID[0]);




        }

        public static List<string> ReadJigui_Project_base(string DBpath, int i)//返回一个机柜名称
        {



            //查询数据库的值
            SQLiteHelperV2 search_value = new SQLiteHelperV2(DBpath);
            string sql_jigui = string.Format("SELECT * FROM project_base  ");
            List<string> JiguiRead = search_value.getDBValues(sql_jigui);

            return JiguiRead;



        }


        public static Dictionary<int, string> Read_Sys_Jigui_Dictionary(string DBpath, int i)//返回一个机柜名称
        {



            //查询数据库的值
            SQLiteHelperV2 search_value = new SQLiteHelperV2(DBpath);
            string sql_jigui = string.Format("SELECT id ,name FROM sys_jigui ");
            Dictionary<int, string> jigui_Dictionary = search_value.getDBValues_v3(sql_jigui);

            return jigui_Dictionary;

        }

        public static Dictionary<int, string> Read_Jigui_Dictionary(string DBpath, int i)//返回一个机柜名称
        {



            //查询数据库的值
            SQLiteHelperV2 search_value = new SQLiteHelperV2(DBpath);
            string sql_jigui = string.Format("SELECT id ,name FROM jigui ");
            Dictionary<int, string> jigui_Dictionary = search_value.getDBValues_v3(sql_jigui);

            return jigui_Dictionary;



        }


        public static List<string> Read_Equip_Foot(string DBpath, string name, string sign_type, string io_sign_type, string configuration)
        {



            //查询数据库的值
            SQLiteHelperV2 search_value = new SQLiteHelperV2(DBpath);

            string sql_jigui = "SELECT * FROM auxi_conn WHERE model = @model  AND sign_type = @sign_type AND io_sign_type = @io_sign_type AND configuration = @configuration";
            SQLiteParameter[] param = new SQLiteParameter[]{
                                   new SQLiteParameter("@model", name),
                                   new SQLiteParameter("@sign_type", sign_type),
                                   new SQLiteParameter("@io_sign_type", io_sign_type),
                                   new SQLiteParameter("@configuration", configuration),

                                 };

           List<string> Equip_Foot = search_value.getDBValues(sql_jigui, param);

            return Equip_Foot;


        }

        //public static List<string> Read_Equip_Type(string DBpath, string name)
        //{



        //    //查询数据库的值
        //    SQLiteHelperV2 search_value = new SQLiteHelperV2(DBpath);

        //    string sql_jigui = "SELECT * FROM auxi_conn WHERE model = @model ";
        //    SQLiteParameter[] param = new SQLiteParameter[]{
        //                           new SQLiteParameter("@model", name),

        //                         };

        //    List<string> Equip_Foot = search_value.getDBValues(sql_jigui, param);

        //    return Equip_Foot;


        //}
        



    }

    class Read_DatableSql
    {
        private static string SourceDBpath = @"../../Source/CXDatabase.db";
        public static DataTable ReadBaseBlockFromDB()
        {
            string sql = "SELECT * FROM block";
            SQLiteHelper sqlhelper = new SQLiteHelper(SourceDBpath, ""); // 参数1: db的绝对路径 参数2: 数据库密码（如果为空则不设置）
            DataTable reader = sqlhelper.ExecuteReader_V3(sql);
            return reader;

        }

        public static DataTable ReadDeviceTable(string DBpath)
        {
            string sql = "SELECT * FROM device";
            SQLiteHelper sqlhelper = new SQLiteHelper(DBpath, ""); // 参数1: db的绝对路径 参数2: 数据库密码（如果为空则不设置）
            DataTable reader = sqlhelper.ExecuteReader_V3(sql);
            return reader;

        }

    }
}
